﻿package core.ui.options
{
    import core.enum.*;
    import core.ui.controls.*;
    import flash.display.*;
    import flash.events.*;

    public class DrawingOptions extends Sprite implements IToolOptions
    {
        var ed:Tuyitu;
        var selected:ActionButton;
        var rect:Sprite;
        var roundrect:Sprite;
        var ellipse:Sprite;
        var line:Sprite;
        var opacity:Dropslider;
        var blendmode:Dropdown;
        var linesize:Dropslider;
        var rectborder:Dropslider;
        var roundrectborder:Dropslider;
        var ellipseborder:Dropslider;
        var roundrectradie:Dropslider;
        var linetrail:Checkbox;
        var rectfill:Checkbox;
        var ellipsefill:Checkbox;
        var roundrectfill:Checkbox;

        public function DrawingOptions(param1:Tuyitu)
        {
            var _loc_13:int = 0;
            this.ed = param1;
            var _loc_2:* = new ActionButton(param1, "rm_draw_rect", Action.DrawRect, new DrawRectOver(), 3, 3);
            _loc_2.addEventListener(MouseEvent.MOUSE_DOWN, this.TypeMouseDown, false, 0, true);
            _loc_2.x = 10;
            _loc_2.y = 3;
            _loc_2.Mark(true);
            this.selected = _loc_2;
            addChild(_loc_2);
            var _loc_3:* = new ActionButton(param1, "rm_draw_round_rect", Action.DrawRoundRect, new DrawRoundRectOver(), 3, 3);
            _loc_3.addEventListener(MouseEvent.MOUSE_DOWN, this.TypeMouseDown, false, 0, true);
            _loc_3.x = 33;
            _loc_3.y = 3;
            addChild(_loc_3);
            var _loc_4:* = new ActionButton(param1, "rm_draw_ellipse", Action.DrawEllipse, new DrawEllipseOver(), 3, 3);
            _loc_4.addEventListener(MouseEvent.MOUSE_DOWN, this.TypeMouseDown, false, 0, true);
            _loc_4.x = 56;
            _loc_4.y = 3;
            addChild(_loc_4);
            var _loc_5:* = new ActionButton(param1, "rm_draw_line", Action.DrawLine, new DrawLineOver(), 4, 4);
            _loc_5.addEventListener(MouseEvent.MOUSE_DOWN, this.TypeMouseDown, false, 0, true);
            _loc_5.x = 79;
            _loc_5.y = 3;
            addChild(_loc_5);
            var _loc_6:* = 107;
            var _loc_7:* = 15;
            var _loc_8:* = new BarSplit();
            _loc_8.x = _loc_6;
            addChild(_loc_8);
            _loc_6 = _loc_6 + (2 + _loc_7);
            var _loc_9:* = new Literal("rm_opacity");
            _loc_9.x = _loc_6;
            _loc_9.y = 2;
            addChild(_loc_9);
            _loc_6 = _loc_6 + _loc_9.width;
            this.opacity = new Dropslider(50, 0, 100, 100);
            this.opacity.x = _loc_6;
            this.opacity.y = 2;
            addChild(this.opacity);
            _loc_6 = _loc_6 + (50 + _loc_7);
            var _loc_10:* = new BarSplit();
            _loc_10.x = _loc_6;
            addChild(_loc_10);
            _loc_6 = _loc_6 + (2 + _loc_7);
            var _loc_11:* = new Literal("rm_mode");
            _loc_11.x = _loc_6;
            _loc_11.y = 2;
            addChild(_loc_11);
            _loc_6 = _loc_6 + _loc_11.width;
            this.blendmode = new Dropdown(90, 90);
            this.blendmode.x = _loc_6;
            this.blendmode.y = 2;
            this.blendmode.AddItem("正常", "normal", true);
            this.blendmode.AddItem("添加", "add");
            this.blendmode.AddItem("透明度", "alpha");
            this.blendmode.AddItem("变暗", "darken");
            this.blendmode.AddItem("差值", "difference");
            this.blendmode.AddItem("排除", "erase");
            this.blendmode.AddItem("强光", "hardlight");
            this.blendmode.AddItem("倒置", "invert");
            this.blendmode.AddItem("层叠", "layer");
            this.blendmode.AddItem("变亮", "lighten");
            this.blendmode.AddItem("正片叠底", "multiply");
            this.blendmode.AddItem("叠加", "overlay");
            this.blendmode.AddItem("屏幕", "screen");
            this.blendmode.AddItem("减淡", "subtract");
            this.blendmode.Bind();
            addChild(this.blendmode);
            _loc_6 = _loc_6 + (this.blendmode.width + _loc_7);
            var _loc_12:* = new BarSplit();
            _loc_12.x = _loc_6;
            addChild(_loc_12);
            _loc_6 = _loc_6 + (2 + _loc_7);
            this.rect = new Sprite();
            this.rect.x = _loc_6;
            addChild(this.rect);
            var _loc_14:* = new Literal("rm_border_size");
            _loc_14.x = _loc_13;
            _loc_14.y = 2;
            this.rect.addChild(_loc_14);
            _loc_13 = _loc_13 + _loc_14.width;
            this.rectborder = new Dropslider(50, 0, 100, 1);
            this.rectborder.x = _loc_13;
            this.rectborder.y = 2;
            this.rect.addChild(this.rectborder);
            _loc_13 = _loc_13 + (50 + _loc_7);
            var _loc_15:* = new BarSplit();
            _loc_15.x = _loc_13;
            this.rect.addChild(_loc_15);
            _loc_13 = _loc_13 + (2 + _loc_7);
            this.rectfill = new Checkbox("rm_fill_shape");
            this.rectfill.x = _loc_13;
            this.rectfill.y = 3;
            this.rectfill.Check();
            this.rect.addChild(this.rectfill);
            this.roundrect = new Sprite();
            this.roundrect.x = _loc_6;
            this.roundrect.visible = false;
            addChild(this.roundrect);
            _loc_13 = 0;
            var _loc_16:* = new Literal("rm_border_size");
            _loc_16.x = _loc_13;
            _loc_16.y = 2;
            this.roundrect.addChild(_loc_16);
            _loc_13 = _loc_13 + _loc_16.width;
            this.roundrectborder = new Dropslider(50, 0, 100, 1);
            this.roundrectborder.x = _loc_13;
            this.roundrectborder.y = 2;
            this.roundrect.addChild(this.roundrectborder);
            _loc_13 = _loc_13 + (50 + _loc_7);
            var _loc_17:* = new BarSplit();
            _loc_17.x = _loc_13;
            this.roundrect.addChild(_loc_17);
            _loc_13 = _loc_13 + (2 + _loc_7);
            var _loc_18:* = new Literal("rm_radie");
            _loc_18.x = _loc_13;
            _loc_18.y = 2;
            this.roundrect.addChild(_loc_18);
            _loc_13 = _loc_13 + _loc_18.width;
            this.roundrectradie = new Dropslider(50, 0, 200, 20);
            this.roundrectradie.x = _loc_13;
            this.roundrectradie.y = 2;
            this.roundrect.addChild(this.roundrectradie);
            _loc_13 = _loc_13 + (50 + _loc_7);
            var _loc_19:* = new BarSplit();
            _loc_19.x = _loc_13;
            this.roundrect.addChild(_loc_19);
            _loc_13 = _loc_13 + (2 + _loc_7);
            this.roundrectfill = new Checkbox("rm_fill_shape");
            this.roundrectfill.x = _loc_13;
            this.roundrectfill.y = 3;
            this.roundrectfill.Check();
            this.roundrect.addChild(this.roundrectfill);
            this.ellipse = new Sprite();
            this.ellipse.x = _loc_6;
            this.ellipse.visible = false;
            addChild(this.ellipse);
            _loc_13 = 0;
            var _loc_20:* = new Literal("rm_border_size");
            _loc_20.x = _loc_13;
            _loc_20.y = 2;
            this.ellipse.addChild(_loc_20);
            _loc_13 = _loc_13 + _loc_20.width;
            this.ellipseborder = new Dropslider(50, 0, 100, 1);
            this.ellipseborder.x = _loc_13;
            this.ellipseborder.y = 2;
            this.ellipse.addChild(this.ellipseborder);
            _loc_13 = _loc_13 + (50 + _loc_7);
            var _loc_21:* = new BarSplit();
            _loc_21.x = _loc_13;
            this.ellipse.addChild(_loc_21);
            _loc_13 = _loc_13 + (2 + _loc_7);
            this.ellipsefill = new Checkbox("rm_fill_shape");
            this.ellipsefill.x = _loc_13;
            this.ellipsefill.y = 3;
            this.ellipsefill.Check();
            this.ellipse.addChild(this.ellipsefill);
            this.line = new Sprite();
            this.line.x = _loc_6;
            this.line.visible = false;
            addChild(this.line);
            _loc_13 = 0;
            var _loc_22:* = new Literal("rm_size");
            _loc_22.x = _loc_13;
            _loc_22.y = 2;
            this.line.addChild(_loc_22);
            _loc_13 = _loc_13 + _loc_22.width;
            this.linesize = new Dropslider(50, 0, 100, 1);
            this.linesize.x = _loc_13;
            this.linesize.y = 2;
            this.line.addChild(this.linesize);
            _loc_13 = _loc_13 + (50 + _loc_7);
            var _loc_23:* = new BarSplit();
            _loc_23.x = _loc_13;
            this.line.addChild(_loc_23);
            _loc_13 = _loc_13 + (2 + _loc_7);
            return;
        }// end function

        private function TypeMouseDown(event:MouseEvent) : void
        {
            if (this.selected != null)
            {
                this.selected.Mark(false);
            }
            this.selected = event.currentTarget as ActionButton;
            this.selected.Mark(true);
            this.rect.visible = false;
            this.roundrect.visible = false;
            this.ellipse.visible = false;
            this.line.visible = false;
            switch((event.currentTarget as ActionButton).action)
            {
                case Action.DrawRect:
                {
                    this.rect.visible = true;
                    break;
                }
                case Action.DrawRoundRect:
                {
                    this.roundrect.visible = true;
                    break;
                }
                case Action.DrawEllipse:
                {
                    this.ellipse.visible = true;
                    break;
                }
                case Action.DrawLine:
                {
                    this.line.visible = true;
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }// end function

        public function get options() : Object
        {
            return {action:this.selected.action, opacity:this.opacity.value / 100, blendmode:this.blendmode.value, rectborder:this.rectborder.value, rectfill:this.rectfill.checked, roundrectborder:this.roundrectborder.value, roundrectradie:this.roundrectradie.value, roundrectfill:this.roundrectfill.checked, ellipseborder:this.ellipseborder.value, ellipsefill:this.ellipsefill.checked, linesize:this.linesize.value};
        }// end function

    }
}
